<template>
  <div class="app-container">
    <div class="filter-container default-box">
      <span>关键字：</span>
      <el-input v-model="listQuery.title" placeholder="请输入关键字" style="width: 240px;" class="filter-item" />
      <el-button class="filter-item" type="primary" icon="el-icon-search" style="margin-left:50px" round>
        查询
      </el-button>
      <el-button class="filter-item" icon="el-icon-refresh-right" round>
        重置
      </el-button>
    </div>
    <div class="default-box">
      <div class="filter-container" @click="createDialog = true;isadd = true">
        <el-button class="filter-item" type="primary" icon="el-icon-plus" round>
          新增
        </el-button>
      </div>
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="list"
        fit
        highlight-current-row
        style="width: 100%;"
      >
        <el-table-column label="标题" min-width="250" show-overflow-tooltip>
          <template>
            <span>消毒测温消毒测温消毒测温消毒测温消毒测温</span>
          </template>
        </el-table-column>
        <el-table-column label="热门" width="300">
          <template>
            <span class="success-color">热门</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="300">
          <template>
            <span class="success-color">正常</span>
          </template>
        </el-table-column>
        <el-table-column label="排序" width="300">
          <template>
            <span>1</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="300" class-name="small-padding fixed-width">
          <template>
            <el-button type="primary" round @click="createDialog = true;isadd = false">
              修改
            </el-button>
            <el-button type="danger" round @click="handleDelete">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
    <!--  新增，修改对话框 -->
    <el-dialog
      :title="isadd?'新增':'修改'"
      :visible.sync="createDialog"
      width="80%"
      custom-class="operate-dialog main-bagcolor"
      top="30vh"
      center
    >
      <el-tabs v-model="activeName" class="default-box" @tab-click="handleClick">
        <el-tab-pane label="基础信息" name="1"><DeliverGoods /></el-tab-pane>
        <el-tab-pane label="扩展信息" name="2"><DeliverGoods /></el-tab-pane>
        <el-tab-pane label="旅游服务" name="3">角色管理</el-tab-pane>
        <el-tab-pane label="日期安排" name="4">定时任务补偿</el-tab-pane>
        <el-tab-pane label="预订须知" name="5">定时任务补偿</el-tab-pane>
      </el-tabs>
    </el-dialog>
  </div>
</template>

<script>
import DeliverGoods from './components/deliver-goods'
import { fetchList } from '@/api/article'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'Adminrole',
  components: { Pagination, DeliverGoods },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        title: ''
      },
      isadd: true, // 是新增 否编辑
      createDialog: true, // 是否展示新增、编辑对话框
      activeName: '1'
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.items
        this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    // 删除
    handleDelete(row, index) {
      this.$confirm('确定要删除该记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        center: true,
        customClass: 'text-center'
      }).then(() => {
        this.$notify({
          title: '成功',
          message: '删除成功',
          type: 'success',
          duration: 2000
        })
        // this.$message({
        //   type: 'success',
        //   message: '删除成功!'
        // })
      }).catch(() => {

      })
      // this.list.splice(index, 1)
    },
    handleClick(tab, event) {
      console.log(tab, event)
    }
  }
}
</script>
<style scoped>
  [class^=el-icon-], [class*=" el-icon-"]{
    font-size: 16px;
  }
  .small-padding i{
    margin-right: 12px;
  }
  .small-padding i:last-child{
    margin-right: 0px;
  }
  ::v-deep .filter-container .el-input--medium .el-input__inner{
    width: 240px;
  }
</style>
